﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using System.Data.Sql;
/// <summary>
/// Summary description for Conexion
/// </summary>
public class Conexion
{
    public Conexion()
    {
        conn = new SqlConnection();
   //     conn.ConnectionString = "Data Source=EST0146TEC043;Initial Catalog=BDPacientes;Integrated Security=True;Pooling=False";
        //conn.ConnectionString = "Data Source=DARI-PC;Initial Catalog=BDPacientes;Integrated Security=True";

        try
        {
            if (Environment.MachineName == "EST0146TEC043")
            conn.ConnectionString = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
            if (Environment.MachineName == "DARI-PC")
                conn.ConnectionString = ConfigurationManager.ConnectionStrings["ConnCasa"].ConnectionString;
        }
        catch (Exception e)
        {

            throw e;
        }
        

    }

    private SqlConnection conn;

    public SqlConnection Conn
    {
        get { return conn; }
        set { conn = value; }
    }



    
    public int loginInto(string user, string pass)
    {
        
       SqlCommand cmd = new SqlCommand("str_log", Conn);
       cmd.CommandType = CommandType.StoredProcedure;
       cmd.Parameters.AddWithValue("@user", user);
       cmd.Parameters.AddWithValue("@pass", pass);

        if (cmd.Connection.State == ConnectionState.Closed)
        {
            cmd.Connection.Open();
        }

        SqlDataAdapter daap = new SqlDataAdapter(cmd);
        //DataTable dt = new DataTable("condet");
        DataTable dt = new DataTable();
        daap.Fill(dt);
        cmd.Connection.Close();
        
        
        
           if (dt.Rows.Count == 0)
           {
               cmd.Connection.Close();
               return 0;
           }
           else
           {
               cmd.Connection.Close();
               return int.Parse(dt.Rows[0][0].ToString());
           }
           
       
     
      }

}
